package email;

import jdbc.*;

import java.util.regex.*;

/**
 * 这是一个方法类，用于注册时的邮箱格式验证及排重验证
 * @author bo
 *
 */
public class CheckEmail {
	public static boolean checkEmail(String emailAddr) {
		String reg = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
		try {
			Pattern pat = Pattern.compile(reg);
			Matcher mat = pat.matcher(emailAddr);
			if (mat.find()) {
				JdbcDao mysql = new JdbcDao();
				if (!mysql.getPersonalInfo(emailAddr, "email").equals(emailAddr)){
					return true;
				}
				else
					return false;
			}
			else return false;
		}catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
